<template>
  <div class="announcement-management">
    <!-- 页面标题 -->
    <div class="page-header">
      <h1>公告管理</h1>
      <button class="btn-add">+ 新增公告</button>
    </div>

    <!-- 搜索和筛选区域 -->
    <div class="search-bar">
      <input
        type="text"
        placeholder="搜索公告标题..."
        class="search-input"
      >
      <button class="btn-search">搜索</button>
      <select class="status-filter">
        <option value="all">全部状态</option>
        <option value="published">已发布</option>
        <option value="draft">草稿</option>
      </select>
    </div>

    <!-- 公告列表 -->
    <div class="announcement-list">
      <table>
        <thead>
          <tr>
            <th>ID</th>
            <th>标题</th>
            <th>发布时间</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <!-- 静态公告数据 -->
          <tr v-for="(item,index) in noticeList" :key="item._id" index="index">
            <td>{{index+1}}</td>
            <td>{{item.title}}</td>
            <td>{{item.publish_time}}</td>
            <td><span class="status published">已发布</span></td>
            <td class="actions">
              <button class="btn-edit">编辑</button>
              <button class="btn-delete">删除</button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>

    <!-- 分页 -->
    <div class="pagination">
      <button class="page-btn">上一页</button>
      <button class="page-btn active">1</button>
      <button class="page-btn">2</button>
      <button class="page-btn">3</button>
      <button class="page-btn">下一页</button>
    </div>
  </div>
</template>

<script setup>
import { getNoticeList } from '@/api/notice';
import { ref } from 'vue';

var noticeList = ref([]);

getNoticeList().then(res => {console.log(res); noticeList.value = res.data.list});
console.log(noticeList);

</script>

<style scoped>
.announcement-management {
  width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: Arial, sans-serif;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

h1 {
  margin: 0;
  color: #333;
}

.btn-add {
  background-color: #42b983;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}

.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  align-items: center;
}

.search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

.btn-search {
  background-color: #2196f3;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}

.status-filter {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #ddd;
}

th, td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

th {
  background-color: #f5f5f5;
  font-weight: bold;
}

.status {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.status.published {
  background-color: #e3f2fd;
  color: #1976d2;
}

.status.draft {
  background-color: #fff8e1;
  color: #ff8f00;
}

.actions {
  display: flex;
  gap: 8px;
}

.btn-edit {
  background-color: #ffc107;
  color: #333;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.btn-delete {
  background-color: #f44336;
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 20px;
}

.page-btn {
  padding: 6px 12px;
  border: 1px solid #ddd;
  background-color: white;
  border-radius: 4px;
  cursor: pointer;
}

.page-btn.active {
  background-color: #2196f3;
  color: white;
  border-color: #2196f3;
}
</style>
